﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IndoReputation.Models.BusinessLogic;
using Telerik.Web.Mvc;
using IndoReputation.Models.BusinessObject;

namespace IndoReputation.Controllers
{
    [Authorize]
    public class OfficeTypeController : BaseController
    {
        //
        // GET: /OfficeType/

        public ActionResult Index()
        {
            ViewData["ajax"] = true;
            ViewData["scrolling"] = true;
            ViewData["paging"] = true;
            ViewData["filtering"] = true;
            ViewData["grouping"] = true;
            ViewData["sorting"] = true;
            ViewData["showFooter"] = true;
            return View(OfficeTypeBOL.GetAllOfficeType());
        }

        [GridAction]
        public ActionResult _Index()
        {
            return View(new GridModel(OfficeTypeBOL.GetAllOfficeType()));
        }

        [HttpGet]
        public ActionResult Add()
        {
            return View(new OfficeType());
        }

        [HttpPost]
        public ActionResult Add(OfficeType model)
        {
            if (ModelState.IsValid)
            {
                model.Name.Trim();
                OfficeTypeBOL.Insert(model);
            }
            //return View(model);
            return RedirectToAction("Index");
        }

        [HttpGet]
        public ActionResult Edit(int officeTypeID)
        {
            OfficeType model = OfficeTypeBOL.GetOfficeTypeById(officeTypeID);
            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(OfficeType model)
        {
            if (ModelState.IsValid)
            {
                model.Name.Trim();
                OfficeTypeBOL.Update(model);
            }
            //return View(model);
            return RedirectToAction("Index");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id)
        {
            //Find a customer with ProductID equal to the id action parameter            
            if (id > 0)
            {
                //Delete the record        
                if (!OfficeTypeBOL.Delete(id))
                {
                    ModelState.AddModelError(String.Empty, @"This OfficeType have Office. Please check again!");
                }
            }

            //Rebind the grid
            return View(new GridModel(OfficeTypeBOL.GetAllOfficeType()));
        }

    }
}
